from fastapi import APIRouter, File
from fastapi.responses import JSONResponse
from pathlib import Path
from datetime import datetime

router = APIRouter(default_response_class=JSONResponse)

# 定义图片存储路径
UPLOAD_DIR = Path("static/log")
# 创建目录（如果不存在）
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)

def set_log(message: str, fileText: str = ''):
    timer = datetime.now().strftime("%Y-%m-%d")
    file_path = f'static/log/{fileText}_{timer}.txt'
    timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    log_entry = f"[{timestamp}]：\n{message}\n\n"
    with open(file_path, 'a', encoding='utf-8') as f:
        f.write(log_entry)
